<template>
  <div class="goodsindex">
    <!-- 检索结果 -->
    <el-row :gutter="20" class="goodsindex-list">
      <el-col :span="24">
        <el-table :data="tableData" style="width: 100%">
          <!-- <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="姓名">
                  <span>{{ props.row.name }}</span>
                </el-form-item>
                <el-form-item label="性别">
                  <span>{{ props.row.gender }}</span>
                </el-form-item>
                <el-form-item label="生日">
                  <span>{{ props.row.birthday }}</span>
                </el-form-item>
                <el-form-item label="电话">
                  <span>{{ props.row.phone }}</span>
                </el-form-item>
                <el-form-item label="邮箱">
                  <span>{{ props.row.email }}</span>
                </el-form-item>
                <el-form-item label="最高薪水">
                  <span>{{ props.row.highestSalary }}</span>
                </el-form-item>
                <el-form-item label="最低薪水">
                  <span>{{ props.row.lowsetSalary }}</span>
                </el-form-item>
                <el-form-item label="自我介绍">
                  <span>{{ props.row.introduce }}</span>
                </el-form-item>
                <el-form-item label="头像">
                  <img :src="'http://'+props.row.headImage" alt="头像" width="100px" height="100px" />
                </el-form-item>
                <el-form-item label="学历">
                  <span>{{ props.row.educationBackground.educationBackground}}</span>
                </el-form-item>
                <el-form-item label="专业名">
                  <span>{{ props.row.major.majorName }}</span>
                </el-form-item>
                <el-form-item label="学校名">
                  <span>{{ props.row.school.schoolName }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column> -->

          <el-table-column label="简历ID" prop="id" width="250"></el-table-column>
          <el-table-column label="姓名" prop="name"></el-table-column>
          <el-table-column label="性别" prop="gender">
            <template mplate slot-scope="scope">{{ scope.row.gender | getType}}</template>
          </el-table-column>
          <el-table-column label="电话" prop="phone"></el-table-column>
          <el-table-column label="邮箱" prop="email"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-popconfirm
                confirm-button-text="确认"
                cancel-button-text="取消"
                icon="el-icon-info"
                icon-color="red"
                title="确定禁用吗？"
                @confirm="banner(scope.row.id)"
              >
                <el-button type="info" size="mini" slot="reference">禁用</el-button>
              </el-popconfirm>
              &nbsp;
              <!-- <el-button type="text" @click="banner(scope.row.id)">禁用</el-button> -->
              <el-popconfirm
                confirm-button-text="确认"
                cancel-button-text="取消"
                icon="el-icon-info"
                icon-color="red"
                title="确定删除吗？"
                @confirm="deleteResume(scope.row.id)"
              >
                <el-button type="danger" size="mini" slot="reference">删除</el-button>
              </el-popconfirm>
              <!-- <el-button type="text" @click="delete(scope.row.id)">删除</el-button> -->
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <div class="block">
              <el-pagination
                  layout="prev, pager, next"
                  :total="pageHelp.total * 10"
                  @current-change="changeCurrentPage"
                  >
              </el-pagination>
          </div>
  </div>
</template>

<script>
let path = "http://localhost";

import axios from "axios";
export default {
  data() {
    return {
      tableData: [],
      pageHelp:{
                currentPage : 1,
                perPageSize : 10,
                total:1,
            },
    };
  },
  filters: {
        getType(val) {
            if(val == 1){
                return val = "男";
            }else if(val == 2){
                return val = "女";
            }else if(val == 3){
                return val = "双性";
            }
            return val = "值异常";
        }
    },
  methods: {
    handleSizeChange() {},
    handleCurrentChange() {},

    warningMessage(info) {
            this.$message({
                message: info,
                type: 'warning'//success、warning
            });
        },
        successMessage(info) {
            this.$message({
                message: info,
                type: 'success'//success、warning
            });
        },
        errorMessage(info) {
            this.$message.error(info);
        },

    //分页查询
    changeCurrentPage(currentPage) {
      console.log(this.pageHelp.currentPage);
      this.pageHelp.currentPage = currentPage;
      axios({
        method: 'get',
        url: path + "/backstage/student/resume",
        params: {
          currentPage: this.pageHelp.currentPage,
          perPageSize: this.pageHelp.perPageSize,
        },
        headers: {
          id: JSON.parse(localStorage.getItem("account")).id,
          token: JSON.parse(localStorage.getItem("account")).token,
        },
        
      }).then(res => {
        if (res.data.code === 500) {
          this.warningMessage("您的权限不足！")
        } else if (res.data.code === 40100) {
          console.log(res.data.data);
          this.tableData = res.data.data.list;
          this.pageHelp.total = res.data.data.pages
        } else {
          this.errorMessage("查询失败！");
        }

        console.log(res);
      }).catch(error => {
        console.log(error);
      })
    },

    //展示所有已启用的用户简历
    listResume() {
      axios({
        method: "GET",
        url: path + "/backstage/student/resume",
        params: {
          currentPage: this.pageHelp.currentPage,
          perPageSize: this.pageHelp.perPageSize,
        },
        headers: {
          id: JSON.parse(localStorage.getItem("account")).id,
          token: JSON.parse(localStorage.getItem("account")).token
        },
       
      })
        .then(res => {
          if (res.data.code === 500) {
            this.warningMessage("您的权限不足！")
          } else if (res.data.code === 40100) {  
            console.log(res.data.data);
            this.tableData = res.data.data.list;
            this.pageHelp.total = res.data.data.pages
          } else {
            this.errorMessage("查询失败！");
          }
          console.log(res);
        })
        .catch(error => {
          console.log(error);
        });
    },

    //禁用某个简历
    banner(id) {
      console.log(id);
      axios({
        method: "PUT",
        url: path + "/backstage/student/resume/" + id,
        headers: {
          id: JSON.parse(localStorage.getItem("account")).id,
          token: JSON.parse(localStorage.getItem("account")).token
        }
      })
        .then(res => {
          if (res.data.code === 500) {
            alert("您没有权限");
          } else if (res.data.code === 30100) {
            console.log(res);
            this.listResume();
          } else {
            alert("更新失败");
          }
          // this.tableData = res.data.data;
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 删除某个简历
    deleteResume(id) {
      console.log(id);
      axios({
        method: "DELETE",
        url: path + "/backstage/student/resume/" + id,
        headers: {
          id: JSON.parse(localStorage.getItem("account")).id,
          token: JSON.parse(localStorage.getItem("account")).token
        }
      })
        .then(res => {
          if (res.data.code === 500) {
            alert("您没有权限");
          } else if (res.data.code === 20100) {
            this.listResume();
          } else {
            alert("删除失败");
          }
          // this.tableData = res.data.data;
        })
        .catch(error => {
          console.log(error);
        });
    }
  },
  created() {
    this.listResume();
  }
};
</script>

<style scoped>
.goodsindex {
  width: 100%;
  min-height: 100%;
  padding: 15px;
  box-sizing: border-box;
}

/* 列表 */
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>